#include<iostream>
using namespace std;

void main(){
	int hour,minute;
	cin >> hour >> minute;
	if(hour > 12)
		cout << hour-12 << ':' << minute << "pm" << endl;
	else
		cout << hour << ':' << minute << "am" << endl;
	system("pause");
}